package com.tanhua.admin.controller;

import com.tanhua.admin.service.ManagerService;
import com.tanhua.model.pojo.UserInfo;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.ws.rs.POST;
import java.util.Map;


@RestController
@RequestMapping("/manage")
public class ManageController {
    @Autowired
    private ManagerService managerService;

//    查询用户列表
//    GET   /manage/users
    @GetMapping("/users")
    public ResponseEntity users(@RequestParam(defaultValue = "1") Integer page
                            ,@RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pr = managerService.findAllUsers(page,pagesize);
        return ResponseEntity.ok(pr);
    }

//    用户基本资料
//    GET   /manage/users/:userID
    @GetMapping("/users/{userId}")
    public ResponseEntity findUserById(@PathVariable("userId") Long userId){
        UserInfo userInfo = managerService.findUserById(userId);
        return ResponseEntity.ok(userInfo);
    }

//    视频记录翻页
//    GET   /manage/videos
    @GetMapping("/videos")
    public ResponseEntity findAllVideos(@RequestParam(defaultValue = "1") Integer page,
                                    @RequestParam(defaultValue = "10") Integer pagesize,
                                    Long uid){
        PageResult pr = managerService.findAllVideos(page,pagesize,uid);
        return ResponseEntity.ok(pr);
    }

//    评论列表翻页
//    GET   /manage/messages/comments


//    动态分页
//    GET   /manage/messages
    @GetMapping("/messages")
    public ResponseEntity messages(@RequestParam(defaultValue = "1") Integer page,
                                   @RequestParam(defaultValue = "10") Integer pagesize,
                                   Long uid,Integer state){
        PageResult pr = managerService.findAllMovements(page,pagesize,uid,state);
        return ResponseEntity.ok(pr);
    }

//    用户冻结操作
//    POST  /manage/users/freeze
    @PostMapping("/users/freeze")
    public ResponseEntity freeze(@RequestBody Map param){
        Map map = managerService.userFreeze(param);
        return ResponseEntity.ok(map);
    }

//    用户解冻操作
//    POST  /manage/users/unfreeze
    @PostMapping("/users/unfreeze")
    public ResponseEntity unfreeze(@RequestBody Map param){
        Map map = managerService.userUnfreeze(param);
        return ResponseEntity.ok(map);
    }
}
